﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
using ConfigurationSettings;

namespace FileSystemControls.ListViewItems
{
    public class ShareListViewItem : FileSystemListViewItem
    {
        //protected Share _currentShare;

        private string _server;
        private string _netName;
        //private string _path;
        private ShareType _shareType;
        private string _remark;

        #region ** Properties **

        private string ParentDirectory
        {
            get
            {
                return Path;
            }
        }

        public new long Length
        {
            get
            {
                return 0;
            }
        }

        public new SizeUnitType FileSizeType
        {
            get
            {
                return _fileSizeType;
            }
        }

        /// <summary>
        /// The name of the computer that this share belongs to
        /// </summary>
        public string Server
        {
            get { return _server; }
        }

        /// <summary>
        /// Local path
        /// </summary>
        //public string Path
        //{
        //    get { return _path; }
        //}

        public string FullName
        {
            get
            {
                if (String.IsNullOrEmpty(_server))
                {
                    return string.Format(@"{0}\{1}", Environment.MachineName, _netName);
                }
                else
                    return string.Format(@"{0}\{1}", _server, _netName);

            }
        }

        //public string Name
        //{
        //    get
        //    {
        //        if (null == _server || 0 == _server.Length)
        //        {
        //            return string.Format(@"{0}\{1}", Environment.MachineName, _netName);
        //        }
        //        else
        //            return string.Format(@"{0}\{1}", _server, _netName);
        //    }
        //}

        public ShareType ShareType
        {
            get { return _shareType; }
        }

        /// <summary>
        /// Comment
        /// </summary>
        public string Remark
        {
            get { return _remark; }
        }

        #endregion

        #region ** Constructors **

        //public ShareListViewItem(Share CurrentEntry)
        public ShareListViewItem(string server, string netName, string path, ShareType shareType, string remark)
        {
            //_currentShare = CurrentEntry;
            if (ShareType.Special == shareType && "IPC$" == netName)
            {
                shareType |= ShareType.IPC;
            }

            _server = server;
            _netName = netName;
            Path = path;
            _shareType = shareType;
            _remark = remark;

            //Use this to get the small Icon
            _smallIcon = FileSystemControls.Resource1.NetShare;
            _isFile = false;

            Text = this.FullName;

            SubItems.Add("<SHARE>");
            SubItems.Add("...");
            Path = this.FullName;

            _fullPath = this.FullName;
            ((FileSystemListViewItem) this).RootName = this.FullName;
            //_thisDirectory = CurrentEntry;
            _isReadOnly = true;
            //_isDotDot = false;

            Name = this.FullName;
            _createDate = DateTime.MinValue; // CurrentEntry.CreationTime;
            _modifyDate = DateTime.MinValue; //CurrentEntry.LastWriteTime;

        }

        //public ShareListViewItem(string SharePath)
        //{
        //}

        #endregion

    }
}
